import apiClient from "@/api/apiClient";

export interface Notification {
	id: number;
	title: string;
	content: string;
	status: string;
	createtime: number;
	updatetime: number;
}

export interface NotificationResponse {
	total: number;
	items: Notification[];
}

export interface ApiResponse<T> {
	status: number;
	message: string;
	time: string;
	data: T;
}

export interface NotificationListParams {
	page: number;
	limit: number;
	keyword?: string;
}

export interface NotificationAddParams {
	title: string;
	content: string;
	status: string;
}

export interface NotificationEditParams {
	id: number;
	title?: string;
	content?: string;
	status?: string;
}

export enum NotificationApi {
	NotificationList = "/notification/index",
	NotificationAdd = "/notification/add",
	NotificationEdit = "/notification/edit",
	NotificationDelete = "/notification/delete",
	NotificationInfo = "/notification/info",
	NotificationHome = "/notification/home",
}

const notificationList = (params: NotificationListParams) =>
	apiClient.get<ApiResponse<NotificationResponse>>({
		url: NotificationApi.NotificationList,
		params,
	});

const notificationAdd = (data: NotificationAddParams) =>
	apiClient.post<ApiResponse<Notification>>({
		url: NotificationApi.NotificationAdd,
		data,
	});

const notificationEdit = (data: NotificationEditParams) =>
	apiClient.put<ApiResponse<Notification>>({
		url: NotificationApi.NotificationEdit,
		data,
	});

const notificationDelete = (id: number) =>
	apiClient.delete<ApiResponse<null>>({
		url: NotificationApi.NotificationDelete,
		data: { id },
	});

const notificationInfo = (id: number) =>
	apiClient.get<ApiResponse<Notification>>({
		url: `${NotificationApi.NotificationInfo}/${id}`,
	});

const notificationHome = () =>
	apiClient.get<ApiResponse<Notification[]>>({
		url: NotificationApi.NotificationHome,
	})

export const notificationService = {
	notificationList,
	notificationAdd,
	notificationEdit,
	notificationDelete,
	notificationInfo,
	notificationHome,
};
